#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

void ChildRun()
{
  int cnt=5;
  while(cnt)
  {
    printf("I am child process,pid:%d,ppid:%d,cnt=%d\n",getpid(),getppid(),cnt);
    sleep(1);
    cnt--;
  }
}

int main()
{
  printf("I am father,pid:%d,ppid:%d\n",getpid(),getppid());
  pid_t id=fork();

  if(id==0)
  {
    //child
    ChildRun();
    printf("child process quit...\n");
    exit(1);
  }

  sleep(7);
  //father
  //pid_t rid=wait(NULL);
  int status=0;
  pid_t rid=waitpid(id,&status,0);
  if(rid>0)
  {
    printf("wait process,rid:%d\n",rid);
  }

  sleep(3);
  printf("father process quit,status:%d,child quit code:%d,child quit signal:%d\n",status,(status>>8)&0xFF,status & 0x7F);

  return 0;
}












//int main()
//{
//  for(int errcode=0;errcode<=255;errcode++)
//  {
//    printf("%d:%s\n",errcode,strerror(errcode));
//  }
//
//  while(1)
//  {
//    printf("I am process,pid:%d,ppid:%d\n",getpid(),getppid());
//    sleep(2);
//    _exit(-1);
//  }
//  return 100;
//}
